package com.yanqu.road.server.cmd.beautyescort;

import com.yanqu.road.pb.beautyescort.BeautyEscortProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.beautyescort.CrossBeautyEscortMgr;
import com.yanqu.road.server.manager.beautyescort.CrossEscortPlayerWrap;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.date.DateHelper;


@Cmd(code = Protocol.C_BEAUTY_ESCORT_USER_UNION_INFO_SYNC, desc = "玩家商会变更")
public class CrossBeautyEscortUserUnionInfoChangeCmd extends CrossCommand {

    BeautyEscortProto.CrossBeautyEscortUserUnionInfoChangeSyncMsg syncMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        syncMsg = BeautyEscortProto.CrossBeautyEscortUserUnionInfoChangeSyncMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        for (long uid : syncMsg.getMemberList()) {
            CrossEscortPlayerWrap playerWrap = CrossBeautyEscortMgr.getEscortPlayer(serverId, uid);
            if(playerWrap != null){
                synchronized (playerWrap.getUserData()){
                    switch (syncMsg.getType()){
                        //创建商会
                        case 1:
                        //加入商会
                        case 2:
                            playerWrap.getUserData().getParams().setJoinUnionTime(DateHelper.getCurrentSecond());
                            playerWrap.getUserData().setUnionLv(syncMsg.getUnionLv());
                            playerWrap.getUserBaseInfo().setUnionAliasId(syncMsg.getUnion().getUnionAliasId());
                            playerWrap.getUserBaseInfo().setUnionUid(syncMsg.getUnionUid());
                            playerWrap.getUserBaseInfo().setUnionName(syncMsg.getUnion().getUnionName());
                            break;
                        //退出商会
                        case 3:
                        //解散商会
                        case 4:
                            playerWrap.getUserData().setUnionLv(0);
                            playerWrap.getUserBaseInfo().setUnionAliasId(0);
                            playerWrap.getUserBaseInfo().setUnionUid("");
                            playerWrap.getUserBaseInfo().setUnionName("");
                            break;
                        //商会升级
                        case 5:
                            playerWrap.getUserData().setUnionLv(syncMsg.getUnionLv());
                            break;
                    }
                }
            }
        }
    }

    @Override
    public void sendData() {

    }
}
